#include "junix.h"
#include <sys/times.h>

void sig_int(int signo)
{
	if(signo==SIGINT)
	{
		struct tms ts;
		clock_t ct=times(&ts);
		setbuf(stdout,NULL);
		printf("clock:%ld\n",ct);

		printf("tms_utime:  %ld\n",ts.tms_utime);
		printf("tms_stime:  %ld\n",ts.tms_stime);
		printf("tms_cutime: %ld\n",ts.tms_cutime);
		printf("tms_cstime: %ld\n\n",ts.tms_cstime);
	}

//	exit(0);
}

void jsleep(int us)
{
	struct timeval tv;
	tv.tv_sec=0;
	tv.tv_usec=us;
	select(1,NULL,NULL,NULL,&tv);
}

void use_system()
{
	int fd=open("X",O_WRONLY|O_CREAT|O_TRUNC,0644);
	if(fd==-1)
		err_sys("open");
	if(-1 == close(fd) )
		err_sys("close");

	if(unlink("X"))
		err_sys("unlink");

	time(NULL);
}

int main(int argc, char **argv)
{

	if( signal(SIGINT,sig_int)==SIG_ERR )
		err_sys("signal");

	for(;;)	{
		use_system();
	}

	return 0;
}

